var kIconHide = 'url(toggle_minus.png)';
var kIconShow = 'url(toggle_plus.png)';
var kTextHide = 'Hide parser output';
var kTextShow = 'Show parser output';

$('.toggle-icon').css('background-image', kIconShow);
$('.toggle-text').text(kTextShow);

var onToggle = function(e) {
  var rowEl = $(e.target).closest('.toggle-row');
  var valueEl = rowEl.siblings('.toggle-value').first();
  var wasHidden = (valueEl.css('display') == 'none');
  valueEl.slideToggle(100 /* milliseconds */, null /* callback */);
  rowEl.find('.toggle-icon').css(
      'background-image', wasHidden ? kIconHide : kIconShow);
  rowEl.find('.toggle-text').text(wasHidden ? kTextHide : kTextShow);
  return false;  // prevent jump-to-top for href="#"
};

$('.toggle-clickable').click(onToggle);
